#ifndef SENSOR_H
#define SENSOR_H

#include <QObject>
class QAccelerometer      ;
class QGyroscope          ;
class QMagnetometer       ;
class QCompass            ;
class QOrientationSensor  ;
class QRotationSensor     ;
class QTiltSensor         ;
class QLightSensor        ;
class QAmbientLightSensor ;
class QProximitySensor    ;
class QGeoPositionInfoSource;
#define SENSORINTERFACE (Sensor::instance())
class Sensor : public QObject
{
    Q_OBJECT
public:
    static Sensor*  instance();
    static void getALL();


    void set_sendCallBack(std::function<void(QByteArray)>);
    explicit Sensor(QObject *parent = nullptr);
private:
    void enLight();
public:
    // getters
    double accelX() const { return m_accelX; }
    double accelY() const { return m_accelY; }
    double accelZ() const { return m_accelZ; }

    double gyroX() const { return m_gyroX; }
    double gyroY() const { return m_gyroY; }
    double gyroZ() const { return m_gyroZ; }

    double magX() const { return m_magX; }
    double magY() const { return m_magY; }
    double magZ() const { return m_magZ; }

    double compassAzimuth() const { return m_compassAzimuth; }

    int orientation() const { return m_orientation; }

    double rotX() const { return m_rotX; }
    double rotY() const { return m_rotY; }
    double rotZ() const { return m_rotZ; }

    double tiltX() const { return m_tiltX; }
    double tiltY() const { return m_tiltY; }

    double lightLux() const { return m_lightLux; }
    void  setLightLux(double);

    int ambientLight() const { return m_ambientLight; }

    bool proximity() const { return m_proximity; }
signals:
    void accelChanged();
    void gyroChanged();
    void magnetometerChanged();
    void compassChanged();
    void orientationChanged();
    void rotationChanged();
    void tiltChanged();
    void lightChanged();
    void ambientLightChanged();
    void proximityChanged();
private:
    QAccelerometer      *m_accel;
    QGyroscope          *m_gyro;
    QMagnetometer       *m_magnetometer;
    QCompass            *m_compass;
    QOrientationSensor  *m_orientationSensor;
    QRotationSensor     *m_rotationSensor;
    QTiltSensor         *m_tiltSensor;
    QLightSensor        *m_lightSensor;
    QAmbientLightSensor *m_ambientLightSensor;
    QProximitySensor    *m_proximitySensor;
    QGeoPositionInfoSource *gps;

    // 数据缓存
    double m_accelX = 0, m_accelY = 0, m_accelZ = 0;
    double m_gyroX = 0, m_gyroY = 0, m_gyroZ = 0;
    double m_magX = 0, m_magY = 0, m_magZ = 0;
    double m_compassAzimuth = 0;
    int m_orientation = -1;
    double m_rotX = 0, m_rotY = 0, m_rotZ = 0;
    double m_tiltX = 0, m_tiltY = 0;
    double m_lightLux = 0;
    int m_ambientLight = 0;
    bool m_proximity = false;


     std::function<void(QByteArray)> _sendCallBack=nullptr;
private:
    // 加速度计
    Q_PROPERTY(double accelX READ accelX NOTIFY accelChanged)
    Q_PROPERTY(double accelY READ accelY NOTIFY accelChanged)
    Q_PROPERTY(double accelZ READ accelZ NOTIFY accelChanged)

    // 陀螺仪
    Q_PROPERTY(double gyroX READ gyroX NOTIFY gyroChanged)
    Q_PROPERTY(double gyroY READ gyroY NOTIFY gyroChanged)
    Q_PROPERTY(double gyroZ READ gyroZ NOTIFY gyroChanged)

    // 磁力计
    Q_PROPERTY(double magX READ magX NOTIFY magnetometerChanged)
    Q_PROPERTY(double magY READ magY NOTIFY magnetometerChanged)
    Q_PROPERTY(double magZ READ magZ NOTIFY magnetometerChanged)

    // 罗盘
    Q_PROPERTY(double compassAzimuth READ compassAzimuth NOTIFY compassChanged)

    // 方向传感器
    Q_PROPERTY(int orientation READ orientation NOTIFY orientationChanged)

    // 旋转传感器
    Q_PROPERTY(double rotX READ rotX NOTIFY rotationChanged)
    Q_PROPERTY(double rotY READ rotY NOTIFY rotationChanged)
    Q_PROPERTY(double rotZ READ rotZ NOTIFY rotationChanged)

    // 倾斜传感器
    Q_PROPERTY(double tiltX READ tiltX NOTIFY tiltChanged)
    Q_PROPERTY(double tiltY READ tiltY NOTIFY tiltChanged)

    // 光线传感器
    Q_PROPERTY(double lightLux READ lightLux NOTIFY lightChanged)

    // 环境光传感器
    Q_PROPERTY(int ambientLight READ ambientLight NOTIFY ambientLightChanged)

    // 距离传感器
    Q_PROPERTY(bool proximity READ proximity NOTIFY proximityChanged)
};

#endif // SENSOR_H
